package com.rpj.stauy.config;

import com.rpj.stauy.service.StreamChatAssistant;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class StreamAiConfig {
    @Bean("chat")
    public ChatModel chatModel(){
        return OpenAiChatModel.builder()
                .modelName("qwen-plus")
                .apiKey(System.getenv("aliQwen_api"))
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }


    //流式大模型原生api，初级api
    @Bean("stream")
    public StreamingChatModel streamingChatModel (){
        return OpenAiStreamingChatModel.builder()
                .modelName("qwen-plus")
                .apiKey(System.getenv("aliQwen_api"))
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }


    //高级调用，增强功能，添加大模型调用功能，流式调用大模型
    @Bean("chatstream")
    public StreamChatAssistant streamChatAssistant(){
        return AiServices.create(StreamChatAssistant.class,streamingChatModel());
    }
}
